﻿@{
    ViewBag.Title = "添加";
    Layout = "../Shared/_Layout.cshtml";
}
@using mscook.mvc;
@model mscook.core.domain.ResourceType
@section JavaScript
{
    <script type="text/javascript" src="@Url.Content("~/scripts/jquery.validate.js")"></script>
    <script type="text/javascript" src="@Url.Content("~/scripts/jquery.validate.unobtrusive.js")"></script>
    <script type="text/javascript" src="@Url.Content("~/scripts/jquery.unobtrusive-ajax.js")"></script>
}

<script type="text/javascript">
    $(function () {
        $("button.modalLoder").live("click", function () {
            var url = $(this).data("url");
            var num = $(this).attr("data-num");
            var modal = $(this).data("link-modal");
            var idInput = $(this).data("link-id");
            var nameInput = $(this).data("link-name");
            var linkbtn = $(this).attr("id");
            var type = $("#ResourceCategory").val();
            $.ajax({
                url: url,
                global: false,
                type: "GET",
                data: { num: num, idInput: idInput, nameInput: nameInput, linkbtn: linkbtn, type: type },
                dataType: "html",
                success: function (data) {
                    $("#" + modal).html(data);
                    $("#" + modal).modal("show");
                }
            });
            return false;
        });
    });
</script>


<div id="resourceTypeModal" class=" modal hide fade form-horizontal">
</div>
<div class="row-fluid sortable">
    <div class="box span12">
        <div class="box-header well">
            <h2></h2>

        </div>
        <div class="box-content">
            @using (Html.BeginForm("Add", "ResourceType", FormMethod.Post, new { enctype = "multipart/form-data", @class = "form-horizontal" }))
            {
                <fieldset>
                    <legend>类型增加</legend>
                    <div class="control-group">
                        <label class="control-label">名称</label>
                        <div class="controls">
                            <div class="input-prepend">
                                @Html.TextBoxFor(resourceType => resourceType.Name, new { size = "16" })
                            </div>
                            @Html.ValidationMessageFor(resourceType => resourceType.Name)
                        </div>
                    </div>
                    <div class="control-group">
                        <label class="control-label">位置</label>
                        <div class="controls">
                            <div class="input-prepend">
                                @Html.TextBoxFor(resourceType => resourceType.EntityIndex, new { size = "16" })
                            </div>
                        </div>
                    </div>
                    <div class="control-group">
                        <label class="control-label">所属资源</label>
                        <div class="controls">
                            <div class="input-prepend">
                                @{
                                    
                var itemList = new List<SelectListItem>();
                itemList.Add(new SelectListItem() { Text = "文章", Value = "Article", Selected = false });
                itemList.Add(new SelectListItem() { Text = "杂志", Value = "Magazine", Selected = false });

                if (ViewData["resourceCategory"] == null)
                {
                                    @Html.DropDownListFor(resourceType => resourceType.ResourceCategory, itemList, new { value = ViewData["resourceCategory"] });
                }
                else
                {
                                    @Html.DropDownListFor(resourceType => resourceType.ResourceCategory, itemList, new { value = ViewData["resourceCategory"], disabled = "true" });
                                    @Html.Hidden("toParent", true)
                }
                                       
                                }
                            </div>
                        </div>
                    </div>
                    <div class="control-group">
                        <label class="control-label">父类型</label>
                        <div class="controls">
                            <div class="input-prepend">

                                <input type="hidden" name="ParentTypeId" id="ParentTypeId"  value="@ViewData["parentId"]" />
                                <input type="text" name="ParentTypeName" readonly="true" id="ParentTypeName" value="@ViewData["parentName"]" />

                            </div>
                            @if (ViewData["parentId"] == null)
                            {
                                <button id="resourceTypeModalBtn" type="button" class="btn btn-primary modalLoder" data-num="1" data-link-name="ParentTypeName" data-link-id="ParentTypeId" data-link-modal="resourceTypeModal" data-url="/weblogin/resourcetype/resourceTypeModal"><i class="icon-edit icon-white"></i></button>
                            }
                        </div>
                    </div>






                    <div class="form-actions">
                        <button type="submit" class="btn btn-primary">保存</button>
                        <button class="btn">Cancel</button>
                    </div>
                </fieldset>
            }
        </div>
    </div>
    <!--/span-->

</div>
